home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / osdep / print.dos < prev    next >
Text File  |  1995-07-14  |  4KB  |  169 lines

  1. /*======================================================================
  2.     print routines
  3.    
  4.     Functions having to do with printing on paper and forking of spoolers
  5.  
  6.     In general one calls open_printer() to start printing. One of
  7.     the little print functions to send a line or string, and then
  8.     call print_end() when complete. This takes care of forking off a spooler
  9.     and piping the stuff down it. No handles or anything here because there's
  10.     only one printer open at a time.
  11.  
  12.  ====*/
  13.  
  14.  
  15. /* protos for routines called out of the pico library */
  16. int      send_printer PROTO((char));            /* Prototypes */
  17. unsigned  short printer_ready PROTO(());
  18. char     *p_printer_error PROTO((unsigned short));
  19.  
  20.  
  21.  
  22. /*----------------------------------------------------------------------
  23.        Open the printer
  24.  
  25.   Args: desc --Description of item to print. Should have on tailing blank.
  26.  
  27. This does most of the work of popen so we can save the standard output of the
  28. command we execute and send it back to the user.
  29.   ----*/
  30. int
  31. open_printer(desc)
  32.      char *desc;
  33. {
  34.     char           prompt[100];
  35.     unsigned short status;
  36.  
  37.     if(status = printer_ready()){        /* 0 means things are OK */
  38.         q_status_message1(SM_ORDER | SM_DING, 3, 5,
  39.               "Error opening printer: %s",
  40.               p_printer_error(status));
  41.         return(-1);
  42.     }
  43.  
  44.     sprintf(prompt, "Print %sto desktop printer", desc == NULL ? "" : desc);
  45.     if(want_to(prompt, 'y', 'n', NO_HELP, 0, 0) == 'n') {
  46.     q_status_message(SM_ORDER, 0, 2, "Print cancelled");
  47.     return(-1);
  48.     }
  49.  
  50.     q_status_message(SM_ORDER, 0, 9, "Printing to desktop printer...");
  51.     display_message('x');
  52.  
  53.     /* init print control structure */
  54.     ps_global->print = (PRINT_S *)fs_get(sizeof(PRINT_S));
  55.     memset(ps_global->print, 0, sizeof(PRINT_S));
  56.  
  57.     ps_global->print->err = 0;
  58.     return(0);
  59. }
  60.  
  61.  
  62.  
  63. /*----------------------------------------------------------------------
  64.      Close printer
  65.   
  66.   If we're piping to a spooler close down the pipe and wait for the process
  67. to finish. If we're sending to an attached printer send the escape sequence.
  68. Also let the user know the result of the print
  69.  ----*/
  70. void
  71. close_printer()
  72. {
  73.     print_char(FORMFEED);
  74.  
  75.     fs_give((void **)&ps_global->print);
  76.  
  77.     q_status_message(SM_ASYNC, 0, 3, "Print command completed");
  78.     display_message('x');
  79. }
  80.  
  81.  
  82.  
  83. /*----------------------------------------------------------------------
  84.      Print a single character
  85.  
  86.   Args: c -- char to print
  87.   Returns: 1 on success, 0 on ps_global->print->err
  88.  ----*/
  89. int
  90. print_char(c)
  91.     int c;
  92. {
  93.     if(!ps_global->print->err
  94.        && (ps_global->print->err = send_printer((char) c)))
  95.       q_status_message1(SM_ORDER, 0, 9, "Print cancelled: %s",
  96.                p_printer_error((unsigned short)ps_global->print->err));
  97.  
  98.     return(!ps_global->print->err);
  99. }
  100.  
  101.  
  102.  
  103. /*----------------------------------------------------------------------
  104.      Send a line of text to the printer
  105.  
  106.   Args:  line -- Text to print
  107.  
  108.   ----*/
  109. void
  110. print_text(line)
  111.     char *line;
  112. {
  113.     register char *c = line;
  114.  
  115.     while(*c != '\0' && !ps_global->print->err)
  116.       print_char(*c++);
  117. }
  118.  
  119.  
  120.  
  121. /*----------------------------------------------------------------------
  122.       printf style formatting with one arg for printer
  123.  
  124.  Args: line -- The printf control string
  125.        a1   -- The 1st argument for printf
  126.  ----*/
  127. void
  128. print_text1(line, a1)
  129.     char *line, *a1;
  130. {
  131.     sprintf(tmp_20k_buf, line, a1);
  132.     print_text(tmp_20k_buf);
  133. }
  134.  
  135.  
  136.  
  137. /*----------------------------------------------------------------------
  138.       printf style formatting with one arg for printer
  139.  
  140.  Args: line -- The printf control string
  141.        a1   -- The 1st argument for printf
  142.        a2   -- The 2nd argument for printf
  143.  ----*/
  144. void
  145. print_text2(line, a1, a2)
  146.     char *line, *a1, *a2;
  147. {
  148.     sprintf(tmp_20k_buf, line, a1, a2);
  149.     print_text(tmp_20k_buf);
  150. }
  151.  
  152.  
  153.  
  154. /*----------------------------------------------------------------------
  155.       printf style formatting with one arg for printer
  156.  
  157.  Args: line -- The printf control string
  158.        a1   -- The 1st argument for printf
  159.        a2   -- The 2nd argument for printf
  160.        a3   -- The 3rd argument for printf
  161.  ----*/
  162. void
  163. print_text3(line, a1, a2, a3)
  164.     char *line, *a1, *a2, *a3;
  165. {
  166.     sprintf(tmp_20k_buf, line, a1, a2, a3);
  167.     print_text(tmp_20k_buf);
  168. }
  169.